import axios from 'axios';

const BASE_URL = 'http://localhost:8080/Rooms';

//增加客房
export const addRoom = async (room) => {
    try {
        const response = await axios.post(BASE_URL,room);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//查询指定酒店id的客房
export const getRoomsByHotelId = async (id) => {
    try {
        const response = await axios.get(`${BASE_URL}/HotelId/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//查询所有客房
export const listRooms = async () => {
    try {
        const response = await axios.get(BASE_URL);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }

};

//删除客房
export const deleteRoom = async (id) => {
    try {
        const response = await axios.delete(`${BASE_URL}/${id}`);
        return response.data;
    } catch (error) {
        console.error('Error listing flights:', error.response ? error.response.data : error.message);
        throw error;
    }
};
// 更新客房状态
export const updateRoom = async (room) => {
    try {
        const response = await axios.put(BASE_URL, room, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error updating room:', error.response ? error.response.data : error.message);
        throw error;
    }
};

//通过酒店房间号更新客房状态
export const updateRoomStatusByHotelIdRoomNum = async (room) => {
    try {
        const response = await axios.put(`${BASE_URL}/updateRoomStatusByHotelIdRoomNum`, room, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
        return response.data;
    } catch (error) {
        console.error('Error updating room:', error.response ? error.response.data : error.message);
        throw error;
    }
};
